<?php

namespace App\Models\SystemManagement;

use App\Models\CommonModel;
use Illuminate\Database\Eloquent\Model;
use App\Models\Constant\Fields;

class Skill extends CommonModel
{
    protected $table = 'skills';
    public $primaryKey = 'id';
    protected $guarded = ['post_id'];

    protected $hidden = ['updated_at','created_at','deleted_at'];

    //查询list
    public function getList($request)
    {
    	$per_page = $request->input('per_page',10);
    	return self::orderBy('id','desc')
                ->where(function($query) use ($request){
                    //检测当前的请求中是否包含name参数
                    $name = $request->input('name','');//职级名称
                    if(!empty($name)) {
                        $query->where('name','like','%'.$name.'%');
                    }
                })
                ->with('postSkill')
                ->paginate($per_page);
    }

    //批量恢复
    public static function recover($ids){
        $query = self::withTrashed()
            ->whereIn('id',$ids)
            ->restore();
        return $query;
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * 岗位职级关系
     */
    public function postSkill(){
        return $this->hasOne(self::$SYSTEM.'\PostSkill',Fields::SKILL_ID)->with('post');
    }

}
